window.onload = function() {
	// Check for LocalStorage support.
	if (localStorage) {
		// Populate the form fields
		populateForm();

		// Get the form
		var form = document.getElementById("quiz");

		// Event listener for when the bookings form is submitted.
		form.addEventListener("submit", function(e) {
			saveData(form);
		});
	}
}

// Save the form data in LocalStorage.

// Attempt to populate the form using data stored in LocalStorage.
function populateForm() {
	// Fetch the input elements.
	var name = document.getElementById("firstName");
	var lastName = document.getElementById("lastName");

	// Retrieve the saved data and update the values of the form
	// fields.
	if (localStorage.getItem("firstName") != null) {
		name.value = localStorage.getItem("firstName");
	}

	if (localStorage.getItem("lastName") != null) {
		lastName.value = localStorage.getItem("lastName");
	}
}
